package com.xqboss.task.redis;

import com.xqboss.task.listener.WsMsgListener;
import com.xqboss.task.listener.WsOnlineListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;

@Configuration
public class RedisSubConfig {

    @Autowired
    private WsMsgListener wsMsgListener;

    @Autowired
    private WsOnlineListener wsOnlineListener;

    @Bean
    public RedisMessageListenerContainer messageListenerContainer(RedisConnectionFactory redisConnectionFactory) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(redisConnectionFactory);

        container.addMessageListener(wsMsgListener, new ChannelTopic("WS:user-msg"));
        container.addMessageListener(wsOnlineListener, new ChannelTopic("WS:user-online"));
        return container;
    }

}
